package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.domain.StrategyReply;
import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.mapper.StrategyReplyMapper;
import cn.wolfcode.trip.base.mapper.TravelCommentMapper;
import cn.wolfcode.trip.base.query.StrategyReplyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StrategyReplyServiceImpl implements IStrategyReplyService {
    @Autowired
    private StrategyReplyMapper strategyReplyMapper;
    @Autowired
    private TravelCommentMapper travelCommentMapper;

    @Override
    public List<StrategyReply> listCommentById(Long replyId) {
        return strategyReplyMapper.selectByReplayId(replyId);
    }

    @Override
    public void saveReplay(StrategyReply strategyReply) {
        strategyReply.setReleaseTime(new Date());
        strategyReplyMapper.saveStrategyReply(strategyReply);
    }

    @Override
    public PageInfo selectForList(StrategyReplyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<StrategyComment> list = strategyReplyMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public void setRead(Long id) {
        strategyReplyMapper.setRead(id);
        travelCommentMapper.setRead(id);
    }

    public Object selectCountById(Long id) {
        return strategyReplyMapper.selectCountById(id);
    }

}
